import request from '../utils/request'

let url = "/admin/table-info";

/**
 * 从SQL新增
 * @param data
 */
export const addFromSql = (data) => {
  return request({
    url: url + "/addFromSql",
    method: 'post',
    data
  })
}

/**
 * 根据id查询字段
 * @param data
 */
export const findColumns = id => {
  return request({
    url: "/admin/column/findByTableId/" + id,
    method: 'get'
  })
}

/**
 * 根据表名查询字段
 * @param data
 */
export const findTables = params => {
  return request({
    url: url + "/page",
    method: 'get',
    params
  })
}

/**
 * 生成Entity
 * @param data
 */
export const createEntity = (tid,project) => {
  return request({
    url: url + "/createEntity/" + tid + "/" + project ,
    method: 'get'
  })
}

/**
 * 生成Vo
 * @param data
 */
export const createVo = (tid,project) => {
  return request({
    url: url + "/createVo/" + tid + "/" + project ,
    method: 'get'
  })
}

/**
 * 生成Mapper.java
 * @param data
 */
export const createMapperJ = (tid,project) => {
  return request({
    url: url + "/createMapper/" + tid + "/" + project ,
    method: 'get'
  })
}

/**
 * 生成Mapper.xml
 * @param data
 */
export const createMapperX = (tid,project) => {
  return request({
    url: url + "/createMapper2/" + tid + "/" + project ,
    method: 'get'
  })
}

/**
 * 逻辑删除
 * @param id
 * @returns {AxiosPromise}
 */
export const deleteOne = (id) => {
  return request({
    url: url + '/' + id,
    method: 'delete',
  })
}



/**
 * 添加
 * @param data
 * @returns {AxiosPromise}
 */
export const add = (data) => {
  return request({
    url: url + "/add",
    method: 'post',
    data
  })
}



/**
 * 批量删除
 * @param ids
 * @returns {*}
 */
export const deleteBatch = (ids) => {
  return request({
    url: url + '/batch/' + ids,
    method: 'delete',
  })
}

/**
 * 编辑
 * @param data
 * @returns {*}
 */
export const edit = (data) => {
  return request({
    url: url,
    method: 'put',
    data
  })
}

/**
 * 分页查询
 * @param params
 * @param data
 * @returns {*}
 */
export const getList = (params, data) => {
  return request({
    url: url + '/page',
    method: 'get',
    params,
    data
  })
}

/**
 * 查询单个
 * @param data
 * @returns {*}
 */
export const findById = (id) => {
  return request({
    url: url + "/" + id,
    method: 'get'
  })
}

/**
 * 新增一个空行
 * @param data
 * @returns {*}
 */
export const addBlankRow = (tid) => {
  return request({
    url: url + "/addBlankRow",
    method: 'get',
    params:{tid}
  })
}
